home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 6
/
FM Towns Free Software Collection 6.iso
/
ms_dos
/
txf
/
src
/
txfcfile.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-08
|
3KB
|
158 lines
/***************
*
* g:\exe\txf\src\txfcfile.c
*/
#include "txf.h"
void read_def(char *own)
{
struct find_t filedata;
char *period, buf[80], *txfdef;
if ((txfdef = getenv("TXFDEF")) != NULL) {
strncpy(buf, txfdef, 80);
if (_dos_findfirst(buf,
_A_ARCH | _A_NORMAL | _A_RDONLY, &filedata) != 0) {
if ((strchr(buf, '\0')-1) != (jstrrchr(buf,'\\')))
strcat(buf, "\\");
strcat(buf, "TXF.DEF");
}
}
else {
strcpy(buf, own);
period=strchr(buf, '.');
strcpy(period, ".DEF");
}
if (_dos_findfirst(buf, _A_ARCH | _A_NORMAL | _A_RDONLY, &filedata) == 0)
read_commandfile(buf);
/*
fprintf(stderr,"Special:DEF FILE:%s\n",buf);
*/
}
void savemem(char chr)
{
fbuf[fbufptr] = chr;
fbufptr++;
if (fbufptr >= (fbufsize * 1024)) {
fbufsize++;
realloc(fbuf, fbufsize*1024);
}
}
void read_commandfile(char *commandfile)
{
FILE *fr;
int paraptr=0;
char *ptr,*txfpath;
char filename[80],chr=0;
struct find_t filedata;
static int fbufbase=0;
if ((txfpath = getenv("TXFPATH")) != NULL) {
strncpy(filename, txfpath, 80);
if ((strchr(filename, '\0') - 1) != (jstrrchr(filename, '\\')))
strcat(filename, "\\");
strcat(filename, commandfile);
}
else {
strcpy(filename, commandfile);
}
ptr = jstrrchr(filename, '\\');
if (ptr == NULL) ptr = filename;
if (strchr(ptr, '.') == NULL) strcat(filename, ".TXF");
if (_dos_findfirst(filename,
_A_ARCH | _A_NORMAL | _A_RDONLY, &filedata) != 0) {
strcpy(filename, commandfile);
if (strchr(ptr, '.') == NULL) strcat(filename, ".TXF");
}
fbufbase = fbufptr;
if (_dos_findfirst(filename,
_A_ARCH | _A_NORMAL | _A_RDONLY, &filedata) == 0) {
fr = fopen(filename, "r");
if (fr == NULL) {
fprintf(stderr, "Info:file=<%s>\n", filename);
errexit("cannot open DEF/command file\n");
}
if (fbufsize == 0) {
fbuf = malloc(1024);
fbufsize = 1;
}
while (chr != EOF) {
chr = getc(fr);
if (chr == EOF) continue;
if (chr == sep) {
chr = getc(fr);
while ((chr != EOF) && (chr != sep)) {
savemem(chr);
chr=getc(fr);
}
savemem(NUL);
}
else if (chr == '#') {
while ((chr != EOF) && (chr != '\n')) chr = getc(fr);
}
else if (chr > ' ') {
paraptr = fbufptr;
while ((chr != EOF) && (chr > ' ')) {
savemem(chr);
chr = getc(fr);
}
savemem(NUL);
if ((fbuf[paraptr] == '-') && ((fbuf[paraptr+1] == 's') ||
(fbuf[paraptr+1] == 'S'))) {
while ((chr != EOF) && (chr <= ' ')) chr = getc(fr);
if (chr != EOF) sep = chr;
savemem(chr);
savemem(NUL);
}
}
}
savesw(fbufbase);
}
else {
if (viewmode > 0) {
fprintf(stderr,
"Warning:commandfile'%s' is not found...\n", filename);
}
}
}
void savesw(int base)
{
static int i = 0;
int j , k;
char *ptr;
char *env;
while ((i > 0) && (para[i-1] == NULL)) i--;
j = i;
ptr = &fbuf[base];
while ((ptr - fbuf) < fbufptr) {
if (*ptr == NUL) {
ptr++;
}
else {
para[i] = ptr;
i += 1;
if (i >= PARA_MAX) errexit("too many parameters");
ptr = strchr(ptr, NUL);
}
}
para[i] = NULL;
if ((env = getenv("TXF")) != NULL) {
if (strcmp(env,"TEST") == 0)
for(k = 0; k < i; k++)
fprintf(stderr, "Info:PARA[%d]=<%s>\n", k, para[k]);
fprintf(stderr, "Info:(i,j)=(%d,%d)\n", i, j);
}
swchk(i - j, ¶[j]);
}